﻿
using System;

namespace Outfish {
	
	/// <summary>
	/// WebScraper wraps this exception around any exception thrown by a WebPage's LoadContent() method.
	/// </summary>
	/// <example>
	/// try{ 
	/// 	_scraper.GetPage<MyPage>(request) 
	/// }catch(LoadContentException){
	/// 	Console.Write("unable to parse/validate MyPage from request " + request.ToString());
	/// }
	/// </example>
	public class LoadContentException : Exception	{
		
		#region constructors
		
		/// <summary>
		/// Called from ScreenScraper.GetWebStream
		/// </summary>
		/// <param name="msg"></param>
		public LoadContentException(string msg ):base(msg){}
		
		public LoadContentException(string msg,Exception innerException ):base(msg,innerException){}
		
		public LoadContentException(
			Exception innerException, 
			Type pageType, 
			IScrapeRequest request,
			string responseSource
		)
			:base("Unable to LoadContent into page: " + pageType.Name, innerException)
		{
			this.ScrapeRequest = request; // attach the real object here where Serailizable is not important
			this.ResponseSource = responseSource;
			this.PageType = pageType;		
		}
		
		#endregion
		
		public IScrapeRequest ScrapeRequest{ get; private set; }

		/// <summary>The string that failed to load.</summary>
		public string ResponseSource{ get; private set; }
		
		/// <summary>The type of the page we are trying load when got the exception.</summary>
		public Type PageType{ get; private set; }

	}
}
